//
//  XDCollectionViewCell.m
//  Le way walkers
//
//  Created by YaZhiLiang on 15/5/25.
//  Copyright (c) 2015年 LTXZ. All rights reserved.
//

#import "XDCollectionViewCell.h"

@implementation XDCollectionViewCell


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.label1 = [[UILabel alloc]init];
        
        [self.contentView addSubview:self.label1];
        
        self.label2 = [[UILabel alloc]init];
        
        [self.contentView addSubview:self.label2];
        
        self.label3 = [[UILabel alloc]init];
        
        [self.contentView addSubview:self.label3];
        
        self.addressLabel = [[UILabel alloc]init];
        
        [self.contentView addSubview:self.addressLabel];
        
        self.abstractLabel = [[UILabel alloc] init];
        
        [self.contentView addSubview:self.abstractLabel];
        
        self.label4 = [[UILabel alloc]init];
        
        [self.contentView addSubview:self.label4];
        
        self.label5 = [[UILabel alloc]init];
        
        [self.contentView addSubview:self.label5];
        
    }
    return self;
}


- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
//    CGFloat f = [[self class] heightWithTxet:self.label1.text Y:24];
//    
//    self.label1.frame = CGRectMake(self.contentView.frame.origin.x + 100, self.contentView.frame.origin.y, self.contentView.frame.size.width - 225, f);
    
    self.label1.font = [UIFont fontWithName:@"Arial-BoldItalicMT" size:24.0];
    
    self.label1.textAlignment = NSTextAlignmentCenter;
    
    self.label1.numberOfLines = 0;
    
//    self.label1.backgroundColor = [UIColor blackColor];
    
//    CGFloat f1 = [[self class] heightWithTxet:self.label2.text Y:15.0];
//    
//    self.label2.frame = CGRectMake(self.label1.frame.origin.x - 80, self.label1.frame.origin.y + self.label1.frame.size.height + 30, self.contentView.frame.size.width - 50, f1);
    
    self.label2.font = [UIFont systemFontOfSize:15.0];
    
    self.label2.numberOfLines = 0;
    
    self.label2.textAlignment = NSTextAlignmentCenter;
    
//    self.label2.backgroundColor = [UIColor blackColor];
    
//    self.label3.frame = CGRectMake(self.label1.frame.origin.x, self.label2.frame.origin.y + self.label2.frame.size.height + 30, self.label1.frame.size.width, self.label1.frame.size.height);
    
    self.label3.font = [UIFont fontWithName:@"Arial-BoldItalicMT" size:24];
    
//    self.label3.backgroundColor = [UIColor blackColor];
    
    self.label3.text = @"景区简介";
    
    self.label3.textAlignment = NSTextAlignmentCenter;
    
//    self.label4.frame = CGRectMake(self.contentView.frame.origin.x, self.label3.frame.origin.y + self.label3.frame.size.height + 20, 50, 30);
    
    self.label4.font = [UIFont fontWithName:@"Arial-BoldItalicMT" size:17.0];
    
//    self.label4.backgroundColor = [UIColor blueColor];
    
    self.label4.text = @"概况";
    
//    CGFloat f2 = [[self class] heightWithTxet:self.abstractLabel.text Y:15.0];
//    
//    self.abstractLabel.frame = CGRectMake(self.contentView.frame.origin.x, self.label4.frame.origin.y + self.label4.frame.size.height + 10, self.contentView.frame.size.width, f2);
    
    self.abstractLabel.font = [UIFont systemFontOfSize:15.0];
    
    self.abstractLabel.numberOfLines = 0;
    
//    self.abstractLabel.backgroundColor = [UIColor blackColor];
    
//    self.label5.frame = CGRectMake(self.contentView.frame.origin.x, self.abstractLabel.frame.origin.y +self.abstractLabel.frame.size.height + 20, self.label4.frame.size.width, self.label4.frame.size.height);
    
    self.label5.font = [UIFont fontWithName:@"Arial-BoldItalicMT" size:17.0];
    
//    self.label5.backgroundColor = [UIColor blueColor];
    
    self.label5.text = @"地址";
    
//    CGFloat f3 = [[self class] heightWithTxet:self.addressLabel.text Y:15.0];
//    
//    self.addressLabel.frame = CGRectMake(self.contentView.frame.origin.x, self.label5.frame.origin.y + self.label5.frame.size.height, self.contentView.frame.size.width, f3);
    
    self.addressLabel.font = [UIFont systemFontOfSize:15.0];
    
    self.addressLabel.numberOfLines = 0;
    
//    self.addressLabel.backgroundColor = [UIColor blackColor];
    
}

+ (CGFloat)heightWithTxet:(NSString *)text Y:(CGFloat)y
{
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:y], NSFontAttributeName, nil];
    
    CGSize size = CGSizeMake([UIScreen mainScreen].bounds.size.width - 30, 5000);
    CGRect rect = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return rect.size.height;
}

+ (CGFloat)heightWithTxetA:(NSString *)texta Y:(CGFloat)y
{
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:y], NSFontAttributeName, nil];
    
    CGSize size = CGSizeMake([UIScreen mainScreen].bounds.size.width -215 , 5000);
    CGRect rect = [texta boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return rect.size.height;
}

- (void)setXdplaceCity:(XDPlaceCityView *)xdplaceCity
{
    if (_xdplaceCity != xdplaceCity) {
        
        [_xdplaceCity release];
        
        _xdplaceCity = [xdplaceCity retain];
    }
    
    self.label1.text = xdplaceCity.name;
    
    self.label2.text = xdplaceCity.recommended_reason;
    
    self.abstractLabel.text = xdplaceCity.description_details;
    
    self.addressLabel.text = xdplaceCity.address;
    
    CGFloat f = [[self class] heightWithTxetA:self.label1.text Y:24.0];
    
    self.label1.frame = CGRectMake(self.contentView.frame.origin.x + 80, self.contentView.frame.origin.y, [UIScreen mainScreen].bounds.size.width - 215, f);
 
    CGFloat f1 = [[self class] heightWithTxet:self.label2.text Y:15.0];
    
    self.label2.frame = CGRectMake(self.label1.frame.origin.x - 80, self.label1.frame.origin.y + self.label1.frame.size.height + 30, [UIScreen mainScreen].bounds.size.width - 30, f1);
    
    self.label3.frame = CGRectMake(self.label1.frame.origin.x, self.label2.frame.origin.y + self.label2.frame.size.height + 30, self.label1.frame.size.width + 20, self.label1.frame.size.height);
    
    CGFloat f2 = [[self class] heightWithTxet:self.abstractLabel.text Y:15.0];
    
     self.label4.frame = CGRectMake(self.contentView.frame.origin.x, self.label3.frame.origin.y + self.label3.frame.size.height + 20, 50, 30);
    
    self.abstractLabel.frame = CGRectMake(self.contentView.frame.origin.x, self.label4.frame.origin.y + self.label4.frame.size.height + 10, [UIScreen mainScreen].bounds.size.width - 30, f2);
    
    self.label5.frame = CGRectMake(self.contentView.frame.origin.x, self.abstractLabel.frame.origin.y +self.abstractLabel.frame.size.height + 20, self.label4.frame.size.width, self.label4.frame.size.height);
    
    
    CGFloat f3 = [[self class] heightWithTxet:self.addressLabel.text Y:15.0];
    
    self.addressLabel.frame = CGRectMake(self.contentView.frame.origin.x, self.label5.frame.origin.y + self.label5.frame.size.height, [UIScreen mainScreen].bounds.size.width - 30, f3);
    
}

@end

